import 'package:flutter/material.dart';
import 'package:untitled/utils/SnackBarHepler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: ScaffoldMessengerGlobalKey,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    //0 ~1
    _animationController = AnimationController(
      vsync: this,
      duration: Duration(seconds: 1),
    );

    //开启
    _animationController.repeat();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('标题'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: Builder(
        builder: (BuildContext context) {
          return Center(
            child: SizedBox(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () {
                      //隐藏 之前的消息  移除
                      ScaffoldMessenger.of(context).hideCurrentSnackBar();

                      //清除所有的
                      ScaffoldMessenger.of(context).clearSnackBars();

                      ScaffoldMessenger.of(context).showSnackBar(
                        SnackBar(
                          content: Text('按钮点击了~~'),
                          duration: Duration(seconds: 4),
                          //背景颜色
                          backgroundColor: Colors.blue,
                          //阴影高度
                          elevation: 20,
                          //浮动效果
                          behavior: SnackBarBehavior.floating,
                          //外边距 floating
                          margin: EdgeInsets.all(40),
                          //内边距
                          padding: EdgeInsets.all(12),
                        ),
                      );
                    },
                    child: Text('提示消息'),
                  ),

                  ElevatedButton(
                    onPressed: () {
                      //隐藏 之前的消息  移除
                      ScaffoldMessenger.of(context).hideCurrentSnackBar();

                      //清除所有的
                      ScaffoldMessenger.of(context).clearSnackBars();

                      ScaffoldMessenger.of(context).showSnackBar(
                        SnackBar(
                          content: Text('按钮点击了~~'),
                          duration: Duration(seconds: 4),
                          //背景颜色
                          backgroundColor: Colors.blue,
                          //阴影高度
                          elevation: 20,
                          //浮动效果
                          behavior: SnackBarBehavior.floating,
                          //外边距 floating
                          margin: EdgeInsets.all(40),
                          //内边距
                          padding: EdgeInsets.all(12),
                          action: SnackBarAction(
                            label: '知道了',
                            backgroundColor: Colors.orange,
                            textColor: Colors.white,
                            onPressed: () {
                              print('点击了');
                            },
                          ),
                        ),
                      );
                    },
                    child: Text('提示消息222'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      SnackBarHelper.showError(context, '测试错误信息~~~');
                    },
                    child: Text('测试错误信息'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      SnackBarHelper.showSuccess(context, '测试成功信息~~~');
                    },
                    child: Text('测试成功信息'),
                  ),

                  ElevatedButton(
                    onPressed: () {
                      SnackBarHelper.showSuccess2('测试成功信息~~~');
                    },
                    child: Text('调用GlobalKey'),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
